package com.gxa.insurance.controller;

import com.gxa.insurance.exception.BusinessException;
import com.gxa.insurance.pojo.Coupon;
import com.gxa.insurance.service.CouponService;
import com.gxa.insurance.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * @author lijunlin
 * @date 2022/6/6
 */
@Api(value = "优惠券模块coupon相关api接口")
@RestController
@RequestMapping("/coupon")
@CrossOrigin
public class CouponController {
    @Autowired
    CouponService couponService;


    @ApiOperation(value = "优惠券添加的方法",produces = "body")
    @PostMapping("/addCoupon")
    public Map addCoupon(@RequestBody Coupon coupon ){
        couponService.addCoupon(coupon);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("优惠券添加成功");
        return jsonResult.getMap();
    }

    @ApiOperation(value = "分页查询所有优惠券的方法",produces = "body")
    @GetMapping("/selectByPage")
    public Map selectByPage(Integer currentPage,Integer pageSize){
        Map<String, Object> maps = couponService.selectByPage(currentPage, pageSize);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询所有数据成功");
        jsonResult.setData(maps);
        return jsonResult.getMap();
    }
    @ApiOperation(value = "根据Id查询优惠券的方法",produces = "query")
    @PostMapping("/selectById")
    public Map selectById(@RequestParam(value = "id",required = true,defaultValue = "1") Integer integer) throws Exception {
        Coupon coupon = couponService.selectById(integer);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("优惠券查询成功");
        jsonResult.setData(coupon);
        return jsonResult.getMap();
    }
    @ApiOperation(value = "优惠券修改的方法",produces = "body")
    @PostMapping("/updateCoupon")
    public Map updateCoupon( @RequestBody Coupon coupon) throws Exception {
        couponService.updateCoupon(coupon);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("优惠券修改成功");
        return jsonResult.getMap();
    }

}
